package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "支付方式模块")
@RestController
@RequestMapping("/admin/payment") //父路径根据接口文档来声明
public class PaymentTypeController {

    @Autowired
    PaymentTypeService paymentTypeService;

    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("/list")
    public Result findAllPaymentType() {
        List<PaymentType> list = paymentTypeService.list();
        return Result.ok(list);  //统一返回结果。所有controller方法，都封装成Result对象返回数据(序列化成JSON)。
    }

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType) {
//        paymentType.setCreateTime(new Date());
//        paymentType.setUpdateTime(new Date());
//        paymentType.setIsDeleted((byte)0);
        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok();
    }

    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam("id") Long id) {
        paymentTypeService.removeById(id);
        return Result.ok();
    }


}
